using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ByteFarm.ImageMetaData.Format;
using ByteFarm.ImageMetaData.Format.Tiff;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace ByteFarm.ImageUtilities.Test
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get { return testContextInstance; }
            set { testContextInstance = value; }
        }

        [TestMethod]
        public void ListMetaData()
        {
            string path = @"D:\dev\ImageUtilities\PB014775.ORF";

            new TiffInfoProvider().GetInfo(path)
                .SelectMany(a => a.DirectoryEntries)
                .ToList()
                .ForEach(o =>
                         Console.WriteLine("{0} {1}", o.Tag, String.Join(",", GetValues(o.GetEnumerator()).ToArray())));
        }


        [TestMethod]
        public void ReadDateCreated()
        {
            string path = @"D:\dev\ImageUtilities\PB014775.ORF";
            TiffInfoProvider provider = new TiffInfoProvider();

            string dts =
                provider.GetInfo(path)
                        .SelectMany(o => o.DirectoryEntries)
                        .Where(o => o.Tag == Tag.DateTime)
                        .Cast<DirectoryEntry<Tag, FieldType, String>>()
                        .SelectMany(o => o.Values).First();

            int[] parts = dts.Split(':', ' ').Select(o => int.Parse(o)).ToArray();


            DateTime dt = new DateTime(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5]);


            Console.WriteLine(dt.ToString());
        }

        public IEnumerable<string> GetValues(IEnumerator enumerator)
        {
            while (enumerator.MoveNext())
            {
                yield return enumerator.Current.ToString();
            }
        }
    }
}